package com.message.tcp.ip.socket.configure.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import org.springframework.stereotype.Repository;

import com.message.tcp.ip.socket.configure.entity.Case;
import com.message.tcp.ip.socket.util.SqliteConnection;
@Repository("caseDaoImp")
public class CaseDaoImp implements CaseDao{
	private static final String ACQ = "ACQ";
	private static final String ISS = "ISS";
	@Override
	public List<Case> getAcqCase() throws SQLException {
		String sql = "SELECT ID, MODE, CODE, NAME, REMARK FROM TESTCASES WHERE MODE = ? ORDER BY ID";
		Connection conn = SqliteConnection.getConnection();
		PreparedStatement stat = conn.prepareStatement(sql);
		stat.setString(1, ACQ);
		ResultSet rs = stat.executeQuery();
		List<Case> cases = new ArrayList<Case>();
		while(rs.next()){
			int id = rs.getInt("ID");
			String mode = rs.getString("MODE");
			String code = rs.getString("CODE");
			String name = rs.getString("NAME");
			String remark = rs.getString("REMARK");
			
			Case c = new Case();
			c.setId(id);
			c.setMode(mode);
			c.setCode(code);
			c.setName(name);
			c.setRemark(remark);
			cases.add(c);
		}
		return cases;
	}

	@Override
	public List<Case> getIssCase() throws SQLException {
		String sql = "SELECT ID, MODE, CODE, NAME, REMARK FROM TESTCASES WHERE MODE = ? ORDER BY ID";
		Connection conn = SqliteConnection.getConnection();
		PreparedStatement stat = conn.prepareStatement(sql);
		stat.setString(1, ISS);
		ResultSet rs = stat.executeQuery();
		List<Case> cases = new ArrayList<Case>();
		while(rs.next()){
			int id = rs.getInt("ID");
			String mode = rs.getString("MODE");
			String code = rs.getString("CODE");
			String name = rs.getString("NAME");
			String remark = rs.getString("REMARK");
			
			Case c = new Case();
			c.setId(id);
			c.setMode(mode);
			c.setCode(code);
			c.setName(name);
			c.setRemark(remark);
			cases.add(c);
		}
		return cases;
	}

}
